package gui;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class database {
    private static Connection conn = null ;
    private  static PreparedStatement  stat = null;
    private static final String driver="com.mysql.jdbc.Driver";
    private static final String username ="root",password="";
    private static String insert,select;
    private static ResultSet rs; 
    private static final  String url="jdbc:mysql://localhost:3306/project";
    public static Connection get_connetion()
               {
                  try
                  {
                      Class.forName(driver);
                    conn = (Connection)DriverManager.getConnection(url,username,password);
                    
                    
                  }
                  catch (Exception e)
                  {
                      System.err.print(e.getMessage()); 
                  }
                   
                 finally
                 {
                     return conn ;
                 }
           }
      
      
    public static ResultSet check(String select) throws SQLException {
           
                try{
                    
                   
                      conn = get_connetion() ;
                       stat = (PreparedStatement)conn.prepareStatement(select);
                      rs=stat.executeQuery(select);
                    
                     
                }catch(Exception e){
                    
                     e.printStackTrace();
                }
               return rs;  

       }
    
    

    public static boolean  insert(String ins)
        {
            conn = get_connetion();
             try
             {
                 
                 stat = (PreparedStatement)conn.prepareStatement(ins);
                 stat.executeUpdate();
             
                 return true; 
             }
             catch (Exception e)
             {
                 e.printStackTrace();
                 return false;
             }
           
           
    }
    
    

    
    
    
}
